import Page
from Page import Music
from Base.Base import Base
from selenium.webdriver.common.by import By


class MusicSearchPage(Base):
    """
    音乐-搜索页面
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧返回按钮
        self.search_back_btn = (By.XPATH, Music.RESOURCE_ID.format('ivBack'))

        # 左侧home键
        self.search_home_btn = (By.XPATH, Music.RESOURCE_ID.format('ivHome'))

        # 语音搜索按钮
        self.search_voice_search_btn = (By.XPATH, Music.RESOURCE_ID.format("tv_start_voice_search"))

        # 语音搜索状态 左边动画
        self.search_voice_recording_img = (By.XPATH, Music.RESOURCE_ID.format("iv_recording_left"))

        # 搜索框
        self.search_search_input = (By.XPATH, Music.RESOURCE_ID.format("et_normal_content"))

        # `立即搜索`按钮
        self.search_search_now_btn = (By.XPATH, Music.RESOURCE_ID.format("search_view_search_now_btn"))

        # `搜索历史`标题
        self.search_search_history_title = (By.XPATH, Page.TEXT.format("搜索历史"))

        # `搜索历史`删除按钮
        self.search_clear_search_history_btn = (By.XPATH, Music.RESOURCE_ID.format("tv_clear"))

        # `搜索历史`列表标题, 从1开始计数
        self.search_list_search_history_title_text = (By.XPATH, Music.search_list_search_history_title_text.format(1))

        # `大家都在搜`标题
        self.search_hot_search_title = (By.XPATH, Page.TEXT.format("大家都在搜"))

        # `大家都在搜`列表标题, 从1开始计数
        self.search_list_hot_search_title_text = (By.XPATH, Music.search_list_hot_search_title_text.format(1))

    def get_list_search_history_title(self, index=1):
        """
        获取指定索引的`搜索历史`列表标题

        :param index: 索引值
        :return: 元素对象
        """
        self.search_list_search_history_title_text = (
            By.XPATH, Music.search_list_search_history_title_text.format(index))

        return self.find_element_o(self.search_list_search_history_title_text)

    def get_list_hot_search_title(self, index=1):
        """
        获取指定索引的`大家都在搜`列表标题

        :param index: 索引值
        :return: 元素对象
        """
        self.search_list_hot_search_title_text = (By.XPATH, Music.search_list_hot_search_title_text.format(index))
        return self.find_element_o(self.search_list_hot_search_title_text)

    def click_voice_search(self):
        """
        点击语音搜索

        :return:
        """
        self.click_element(self.search_voice_search_btn)

    def click_back(self):
        """
        点击左侧返回键

        :return:
        """
        self.click_element(self.search_back_btn)

    def click_home(self):
        """
        点击左侧home键

        :return:
        """
        self.click_element(self.search_home_btn)

    def input_search(self, text):
        """
        输入搜索内容

        :param text: 搜索内容
        :return: None
        """
        self.input_text(self.search_search_input, text)

    def is_display_voice_search(self):
        """
        是否展示语音搜索按钮

        :return: bool
        """
        return self.is_display(self.search_voice_search_btn)

    def is_display_recording(self):
        """
        是否展示录音状态

        :return:
        """
        return self.is_display(self.search_voice_recording_img)


if __name__ == '__main__':
    pass
